package com.winchain.chainbill.bill.biz.repurchase.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbRpur;
import com.winchain.chainbill.bill.base.service.CbRpurService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillRpurSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbRpur>> {
	@Autowired
	private CbRpurService cbRpurService;

	public void onApplicationEvent(BillEvent<CbRpur> t) {
		CbRec record = t.getBill().getRec();
		CbRpur cbRpur = (CbRpur) t.getBill().getSource();
		if (cbRpur != null) {
			cbRpur.setOptSeq(record.getOptSeq());
			this.cbRpurService.saveOrUpdate(cbRpur);
		}
	}
}
